package com.service.lx;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.lx.DELIVERRECORD_copyDAO;
import com.dao.lx.RepairorderDAO;
import com.entity.DELIVERRECORD_copy;
import com.entity.Repairorder;
import com.service.ServiceException;


@Service
@Transactional(rollbackFor = Exception.class)
public class DELIVERRECORD_copyService {
	@Autowired
	private DELIVERRECORD_copyDAO DELIVERRECORD_copyDAO;
	@Autowired
	private RepairorderDAO repairorderDAO;
	/**
	 * 添加/修改/逻辑删除
	 * @param process
	 * @throws ServiceException
	 */
	public void addAndUpdateDELIVERRECORD_copy(DELIVERRECORD_copy DELIVERRECORD_copy) throws ServiceException{
		try {
			//判断维修工单是否存在
			if(DELIVERRECORD_copy.getRepairorderId()!=null){
				Repairorder repairorder=repairorderDAO.findOne(DELIVERRECORD_copy.getRepairorderId());
				if(repairorder!=null){
					DELIVERRECORD_copy DELIVERRECORD_copy2=DELIVERRECORD_copyDAO.findByRepairorder(repairorder);
					if(DELIVERRECORD_copy2!=null){
						DELIVERRECORD_copy.setDrId(DELIVERRECORD_copy2.getDrId());
					}
					DELIVERRECORD_copy.setRepairorder(repairorder);
				}else{
					DELIVERRECORD_copy.setRepairorder(null);
				}
			}
			DELIVERRECORD_copyDAO.save(DELIVERRECORD_copy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 删除
	 * @param drId
	 * @throws ServiceException
	 */
	public void deleteDELIVERRECORD_copy(Long drId) throws ServiceException{
		try {
			DELIVERRECORD_copyDAO.delete(drId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 单条查询
	 * @param processId
	 * @return
	 */
	public DELIVERRECORD_copy findOne(Long drId) {
		return DELIVERRECORD_copyDAO.findOne(drId);
	}

}
